package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortString {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "汉武大帝", "秦始皇", "雍正", "爱新觉罗雍正");
        System.out.println("list原始数据:" + list);
        Collections.shuffle(list);
        System.out.println("打乱后,list的数据:" + list);
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        });
        System.out.println("排序后的list数据:" + list);
        Collections.sort(list, (s1, s2) -> s2.length() - s1.length());
        System.out.println("倒叙后的list数据:" + list);
        System.out.println("------------------------------------------------");
        List<String> list1 = new ArrayList<>();
        Collections.addAll(list1, "Kobe", "KD", "Curry", "James", "MichealJordan");
        Collections.sort(list1);
        System.out.println(list1);
    }
}
